package _interview150;

/**
 * 169. 多数元素
 */
public class No169 {
    public int majorityElement(int[] nums) {
        int ans = 0, count = 0;
        for (int num : nums) {
            if (count == 0) {
                ans = num;
                count = 1;
            } else if (ans != num) count--;
            else count++;
        }
        return ans;
    }
}
